from pandas_vlookup.vlookup import PandasVlookup
import pandas as pd

def exact_match_example():
    """精确匹配示例"""
    vlookup = PandasVlookup()

    # 读取Excel文件
    df1 = vlookup.read_excel('table1.xlsx')
    df2 = vlookup.read_excel('table2.xlsx')

    # 精确匹配合并
    result = vlookup.merge_exact(
        df1,
        df2,
        left_on='ID',
        right_on='ID',
        how='left'
    )

    # 保存结果
    vlookup.save_excel(result, 'result_exact.xlsx')

def fuzzy_match_example():
    """模糊匹配示例"""
    vlookup = PandasVlookup()

    # 读取Excel文件
    df1 = vlookup.read_excel('table1.xlsx')
    df2 = vlookup.read_excel('table2.xlsx')

    # 模糊匹配合并
    result = vlookup.merge_fuzzy(
        df1,
        df2,
        left_on='Date',
        right_on='Date',
        tolerance=pd.Timedelta('1D'),  # 1天的容差
        direction='nearest'
    )

    # 保存结果
    vlookup.save_excel(result, 'result_fuzzy.xlsx')

if __name__ == '__main__':
    # 精确匹配示例
    exact_match_example()

    # 模糊匹配示例
    fuzzy_match_example()
